<?php
/**
 * Created by PhpStorm.
 * User: 14775
 * Date: 2017/8/30
 * Time: 10:22
 */

namespace Common\Model;


class MembersModel extends CommonModel
{
    //自动验证
    protected $_validate = array();

    /*
     * 获取会员信息（如不存在，则生成新会员）
     */
    public function getMember($openid)
    {
        $member = self::where(array('wx_openid' => $openid))->find();
        return $member;
    }

    public function getMemberByMobile($mobile)
    {
        $member = self::where(array('telephone' => $mobile))->find();
        return $member;
    }

    public function getMemberByCode($member_code)
    {
        $member = self::where(array('member_code' => $member_code))->find();
        return $member;
    }

    public function register($member)
    {
        return self::add($member);
    }

    public function modify($mobile, $params)
    {
        $member = new self();
        if ($params) {
            foreach ($params as $key =>$val){
                $member->$key = $val;
            }
            $member->where(array('telephone'=>$mobile))->save();
        }
        return true;

    }

    public function syncIntegral($member_code, $integral)
    {
        $member = new self();
        $member->integral = $integral;
        $member->where(array('member_code'=>$member_code))->save();
        return true;

    }
}